<template>
  <div class="back-button" @click="handleBack">
    <div class="back-icon">
      <svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
        <path d="M19 12H5M12 19L5 12L12 5" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
      </svg>
    </div>
    <span v-if="showText" class="back-text">{{ text }}</span>
  </div>
</template>

<script setup>

const props = defineProps({
  text: {
    type: String,
    default: '返回'
  },
  showText: {
    type: Boolean,
    default: false
  },
  customBack: {
    type: Function,
    default: null
  }
})

const emit = defineEmits(['back'])

const handleBack = () => {
  if (props.customBack) {
    props.customBack()
  } else {
    emit('back')
    // 使用uni-app的導航API
    uni.navigateBack({
      delta: 1
    })
  }
}
</script>

<style scoped>
.back-button {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 20px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  backdrop-filter: blur(10px);
  cursor: pointer;
  transition: all 0.3s ease;
  position: fixed;
  top: 60px;
  left: 16px;
  z-index: 1000;
}

.back-button:hover {
  background: rgba(255, 255, 255, 1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transform: translateY(-1px);
}

.back-button:active {
  transform: translateY(0);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.back-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  color: #333;
  transition: color 0.3s ease;
}

.back-button:hover .back-icon {
  color: #4a90e2;
}

.back-text {
  margin-left: 4px;
  font-size: 14px;
  color: #333;
  font-weight: 500;
}

/* 手機端適配 */
@media (max-width: 768px) {
  .back-button {
    top: 50px;
    left: 12px;
    padding: 6px 10px;
  }
  
  .back-text {
    font-size: 13px;
  }
}

/* 小屏幕手機適配 */
@media (max-width: 375px) {
  .back-button {
    top: 45px;
    left: 8px;
    padding: 5px 8px;
  }
  
  .back-icon svg {
    width: 20px;
    height: 20px;
  }
  
  .back-text {
    font-size: 12px;
  }
}
</style>
